"use strict";
cc._RF.push(module, '78191tmYM1PfZyPmF52ZY59', 'level29');
// scripts/modes/normalMode/levelAvoid/level29/level29.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../../../engines/gameEngine");
var data_control_1 = require("../../../../engines/libs/data_control");
var levelAvoidPlayer_1 = require("../base/levelAvoidPlayer");
var levelAvoidBase_1 = require("../levelAvoidBase");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var level29 = /** @class */ (function (_super) {
    __extends(level29, _super);
    function level29() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.waveNode = [];
        return _this;
    }
    level29.prototype.Init = function (info) {
        return __awaiter(this, void 0, Promise, function () {
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0: return [4 /*yield*/, _super.prototype.Init.call(this, info)];
                    case 1:
                        _a.sent();
                        gameEngine_1.default.getManagers().soundMgr.loadSoundBundle("fontChase");
                        return [2 /*return*/];
                }
            });
        });
    };
    level29.prototype.setGameStart = function () {
        _super.prototype.setGameStart.call(this);
        // managers().soundMgr.playSound("level29/sound/startGame", () => { })
        this.wave1();
        // this.wave3();
    };
    level29.prototype.wave1 = function () {
        var _this = this;
        var zuoUpPos = [
            cc.v2(-1, 0).rotateSelf(40 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(55 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(70 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(85 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(100 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(115 * Math.PI / 180),
        ];
        var youUpPos = [
            cc.v2(-1, 0).rotateSelf(90 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(100 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(110 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(120 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(130 * Math.PI / 180),
            cc.v2(-1, 0).rotateSelf(140 * Math.PI / 180),
        ];
        var zuoDownPos = [
            cc.v2(1, 0).rotateSelf(90 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(100 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(110 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(120 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(130 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(140 * Math.PI / 180),
        ];
        var youDownPos = [
            cc.v2(1, 0).rotateSelf(60 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(70 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(80 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(90 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(100 * Math.PI / 180),
            cc.v2(1, 0).rotateSelf(110 * Math.PI / 180),
        ];
        var chats = ["咀", "嚼", "吞", "咽", "啖", "肉", "食", "吃", "喝", "饕", "餮"];
        this.scheduleOn(function () {
            var _loop_1 = function (j) {
                var _loop_2 = function (i) {
                    var chat = data_control_1.default.getRandItemOfArray(chats);
                    _this.scheduleOn(function () {
                        var LabNode = _this.newLabNode();
                        var pos = j % 2 == 0 ? zuoUpPos[i] : youUpPos[i];
                        LabNode.init(chat, _this.player.getComponent(levelAvoidPlayer_1.default), {
                            moveType: 1,
                            moveSpeed: 5,
                            startPos: cc.v2(0, 355),
                            moveDirection: pos
                        }, _this);
                        LabNode.startAvoid();
                        _this.waveNode.push(LabNode.node);
                        _this.scheduleOn(function () {
                            gameEngine_1.managers().soundMgr.playSound("fontChase/shot", function () {
                            });
                        }, 0.5);
                    }, j * 0.5);
                };
                for (var i = 0; i < 6; i++) {
                    _loop_2(i);
                }
            };
            for (var j = 0; j < 3; j++) {
                _loop_1(j);
            }
        }, 1);
        this.scheduleOn(function () {
            var _loop_3 = function (j) {
                var _loop_4 = function (i) {
                    var chat = data_control_1.default.getRandItemOfArray(chats);
                    _this.scheduleOn(function () {
                        var LabNode = _this.newLabNode();
                        var pos = j % 2 == 0 ? youDownPos[i] : zuoDownPos[i];
                        LabNode.init(chat, _this.player.getComponent(levelAvoidPlayer_1.default), {
                            moveType: 1,
                            moveSpeed: 5,
                            startPos: cc.v2(0, -355),
                            moveDirection: pos
                        }, _this);
                        LabNode.startAvoid();
                        _this.waveNode.push(LabNode.node);
                        _this.scheduleOn(function () {
                            gameEngine_1.managers().soundMgr.playSound("fontChase/shot", function () {
                            });
                        }, 0.3);
                    }, j * 0.5);
                };
                for (var i = 0; i < 6; i++) {
                    _loop_4(i);
                }
            };
            for (var j = 0; j < 3; j++) {
                _loop_3(j);
            }
        }, 4);
        this.scheduleOn(function () {
            for (var _i = 0, _a = _this.waveNode; _i < _a.length; _i++) {
                var node = _a[_i];
                node.destroy();
            }
            _this.waveNode = [];
            _this.wave4();
        }, 8);
    };
    level29.prototype.wave2 = function () {
        // managers().soundMgr.playSound("level29/sound/mztc")
        // cc.tween(this.node_ma.node)
        //     .to(0.2, { scale: 0 })
        //     .delay(1)
        //     .call(() => {
        //         this.node_ma.lab.string = "人"
        //         this.node_ma.node.getChildByName("maren").active = true;
        var _this = this;
        //         managers().soundMgr.playSound("level29/sound/maren")
        //         this.scheduleOn(() => {
        //             this.node_ma.node.getChildByName("maren").active = false;
        //         }, 4)
        //     })
        //     .to(0.2, { scale: 1 })
        //     .start()
        var strList = [
            "你\n好\n，\n小\n肥\n猫",
            "心\n广\n体\n肥",
            "体\n重\n焦\n虑",
            "胖\n得\n相\n亲\n对\n象\n连\n夜\n跑\n路\n",
            "你\n这\n么\n胖\n，\n根\n本\n买\n不\n到\n衣\n服",
            "你\n胖\n成\n这\n样\n，\n还\n能\n嫁\n的\n出\n去",
            "你\n走\n过\n的\n时\n候\n，\n我\n感\n觉\n地\n在\n颤\n抖",
            "你\n不\n胖\n，\n只\n是\n照\n片\n的\n空\n间\n小\n了\n点",
            "每\n天\n都\n在\n横\n向\n发\n展",
            "电\n梯\n超\n重\n，\n大\n家\n全\n都\n看\n着\n你",
            "一\n白\n遮\n百\n丑\n，\n一\n胖\n毁\n所\n有\n",
            "只\n是\n骨\n架\n大\n，\n才\n不\n是\n胖\n",
            "不\n好\n意\n思\n，\n这\n里\n没\n有\n你\n的\n尺\n码",
            "站\n远\n点\n，\n你\n挡\n我\n信\n号\n了",
            "燕\n瘦\n环\n肥\n，\n你\n是\n最\n后\n一\n项"
        ];
        var posYList = [-250, -200, -150, -75, 0, 75, 150, 200, 250];
        var yList = posYList.concat();
        var tempStrList = strList.concat();
        strList.sort(function (a, b) { return Math.random() < 0.5 ? 1 : -1; });
        for (var i = 0; i < 30; i++) {
            this.scheduleOn(function () {
                // cc.tween(this.node)
                //     .delay(i * 0.5)
                // .call(() => {
                var x = Math.random() < 0.5 ? -1000 : 1000;
                if (yList.length == 0)
                    yList = posYList.concat();
                var indexof = Math.floor(data_control_1.default.getRandNumberOfArrayTwo([0, yList.length]));
                var startPos = cc.v2(yList[indexof], x);
                yList.splice(indexof, 1);
                var moveDirection = cc.v2(0, x > 0 ? -1 : 1);
                var LabNode = _this.newLabNode();
                if (tempStrList.length == 0)
                    tempStrList = strList.concat();
                var strIndex = Math.floor(data_control_1.default.getRandNumberOfArrayTwo([0, tempStrList.length]));
                var str = tempStrList[strIndex];
                tempStrList.splice(strIndex, 0);
                LabNode.init(str, _this.player.getComponent(levelAvoidPlayer_1.default), {
                    moveType: 1,
                    moveSpeed: 5,
                    startPos: startPos,
                    moveDirection: moveDirection
                }, _this);
                LabNode.startAvoid();
                _this.waveNode.push(LabNode.node);
                // })
                // .start()
            }, i * 0.5);
        }
        this.scheduleOn(function () {
            for (var _i = 0, _a = _this.waveNode; _i < _a.length; _i++) {
                var node = _a[_i];
                node.destroy();
            }
            _this.waveNode = [];
            _this.wave3();
        }, 20);
    };
    level29.prototype.wave3 = function () {
        var _this = this;
        // this.node_ma.startAvoid(false);
        var labList = ["肥", "胖", "丑", "油", "腻"];
        var posList = [cc.v2(-280, 280), cc.v2(-280, 0), cc.v2(-280, -280), cc.v2(280, 280), cc.v2(280, 0), cc.v2(280, -280)];
        for (var i = 0; i < labList.length; i++) {
            var LabNode = this.newLabNode();
            this.waveNode.push(LabNode.node);
            LabNode.init(labList[i], this.player.getComponent(levelAvoidPlayer_1.default), {
                moveType: 0,
                moveSpeed: 1.5,
                startPos: posList[i] //cc.v2(data_control.getRandNumberOfArrayTwo([-280, 280]), data_control.getRandNumberOfArrayTwo([-380, 380]))
            }, this, 1.25);
            LabNode.startAvoid();
        }
        this.scheduleAny(function () {
            var lab = labList[Math.floor(data_control_1.default.getRandNumberOfArrayTwo([0, labList.length]))];
            var LabNode = _this.newLabNode();
            _this.waveNode.push(LabNode.node);
            LabNode.node.scale = 1.5;
            LabNode.init(lab, _this.player.getComponent(levelAvoidPlayer_1.default), {
                moveType: 0,
                moveSpeed: 1.5,
                startPos: cc.v2(data_control_1.default.getRandNumberOfArrayTwo([-280, 280]), data_control_1.default.getRandNumberOfArrayTwo([-380, 380]))
            }, _this, 1.25);
            LabNode.startAvoid();
        }, 0.5);
    };
    level29.prototype.wave4 = function () {
        var _this = this;
        var posAry = [
            cc.v2(-255, 355),
            cc.v2(255, 355),
            cc.v2(-255, -355),
            cc.v2(255, -355),
        ];
        var posAryCopy = data_control_1.default.randomSortArray(posAry.concat());
        var chats = ["披萨", "熏火腿", "五香豆", "担担面", "叉烧包", "虾饺", "章鱼小丸子", "紫菜", "奥尔良烤翅", "狗不理包子", "黑森林", "布朗尼", "提拉米苏", "牛排", "牛肉干", "奶昔", "奶茶", "双皮奶", "手抓饼", "巧克力", "咖喱鱼丸", "鱼腐", "寿司", "北极贝", "三文鱼", "冰激凌", "炒面", "三文治", "鸡翅", "意大利面", "烧烤", "鳗鱼饭三吃", "拉面", "熟寿司", "荞麦面"];
        var createCount = 10;
        var interval = 1;
        var chatCopy = data_control_1.default.randomSortArray(chats.concat());
        for (var i = 0; i < createCount; i++) {
            this.scheduleOn(function () {
                if (chatCopy.length <= 0) {
                    chatCopy = data_control_1.default.randomSortArray(chats.concat());
                }
                var chat = chatCopy.pop();
                var LabNode = _this.newLabNode();
                if (posAryCopy.length <= 0) {
                    posAryCopy = data_control_1.default.randomSortArray(posAry.concat());
                }
                var pos = posAryCopy.pop();
                var dir = _this.player.getPosition().sub(pos).normalize();
                LabNode.init(chat, _this.player.getComponent(levelAvoidPlayer_1.default), {
                    moveType: 1,
                    moveSpeed: 6,
                    startPos: pos,
                    moveDirection: dir
                }, _this);
                LabNode.startAvoid();
                _this.waveNode.push(LabNode.node);
            }, i * interval);
        }
        this.scheduleOn(function () {
            _this.wave2();
        }, createCount * interval + 3);
    };
    level29.prototype.Lose = function (time) {
        this.unscheduleAllCallbacks();
        var pos = this.player;
        var jumpTime = cc.v3(100, -1000).sub(this.player.position).mag() / 800;
        // managers().soundMgr.playSound("fontChase/death").then();
        cc.tween(this.player)
            .parallel(cc.tween(this.player).bezierTo(jumpTime, this.player.getPosition(), cc.v2(this.player.x + 200, this.player.y + 500), cc.v2(this.player.x + 400, this.player.y - 1000)), cc.tween(this.player).to(4, { angle: -3000 }))
            .start();
        _super.prototype.Lose.call(this, jumpTime);
    };
    level29.prototype.Win = function (time, jyIndex, userStr) {
        var _this = this;
        this.unscheduleAllCallbacks();
        var endScale = this.player.scale;
        gameEngine_1.managers().soundMgr.playSound("fontChase/win", function () { });
        cc.tween(this.player)
            .to(0.2, { scale: 0.6 })
            .call(function () {
            _this.player.getChildByName("spwin").active = true;
        })
            .delay(2)
            .call(function () {
            var bo = _this.player.getChildByName("bo");
            bo.active = true;
            cc.tween(bo)
                .to(1, { scale: 5 })
                .call(function () {
                bo.active = false;
            })
                .start();
        })
            .to(0.2, { scale: 1 })
            .call(function () {
            var _loop_5 = function (node) {
                cc.tween(node)
                    .to(0.1, { scale: 1.1, opacity: 255 })
                    .to(0.1, { scale: 1, opacity: 100 })
                    .to(0.1, { scale: 1.1, opacity: 255 })
                    .to(0.1, { scale: 1, opacity: 100 })
                    .to(0.3, { scaleX: 1.2, scaleY: 0.8, opacity: 0 })
                    .call(function () {
                    node.destroy();
                })
                    .start();
            };
            for (var _i = 0, _a = _this.waveNode; _i < _a.length; _i++) {
                var node = _a[_i];
                _loop_5(node);
            }
            _super.prototype.Win.call(_this, 3);
        })
            .start();
    };
    level29 = __decorate([
        ccclass
    ], level29);
    return level29;
}(levelAvoidBase_1.default));
exports.default = level29;

cc._RF.pop();